package com.gsta.ifishery.common.util;

import java.net.InetSocketAddress;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

/**
 * netty服务工具类 . <br>
 * 
 * @author hkb
 */
public final class NettyServerUtils {

    private NettyServerUtils() {
        super();
    }

    /**
     * 获取客户端ip(不含端口号)
     * 
     * @param ctx
     * @return
     */
    public static String getClientIp(ChannelHandlerContext ctx) {
        Channel incoming = ctx.channel();
        InetSocketAddress insocket = (InetSocketAddress) incoming.remoteAddress();
        return insocket.getAddress().getHostAddress();
    }

    /**
     * 获取客户端ip(含端口号)
     * 
     * @param ctx
     * @return
     */
    public static String getWholeClientIp(ChannelHandlerContext ctx) {
        Channel incoming = ctx.channel();
        return incoming.remoteAddress().toString().replace("/", "");
    }

}
